package cn.jhc.sevlet;//修改缴费信息

import java.io.IOException;
import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.jhc.bean.Payment;
import cn.jhc.bean.Student;
import cn.jhc.dao.PaymentDao;
import cn.jhc.dao.StudentDao;
import cn.jhc.dao.impl.PaymentDaoImpl;
import cn.jhc.dao.impl.StudentDaoImpl;

/**
 * Servlet implementation class AlterpaymentServlet
 */
@WebServlet("/user/teacher/alterpayment.do")
public class AlterpaymentServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AlterpaymentServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("UTF-8");
		HttpSession session = request.getSession();
		int id = Integer.valueOf(request.getParameter("id"));
		String sno = request.getParameter("sno");
		StudentDao studentDao = new StudentDaoImpl();
		Student student = studentDao.getStudent(sno);
		BigDecimal money = new BigDecimal(request.getParameter("money"));
		String paynumber = request.getParameter("paynumber");
		String remark = request.getParameter("remark");
		Payment payment = new Payment();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");	
		try {
			Date paytime = sdf.parse(request.getParameter("paytime"));
			payment.setTime(paytime);
		} catch (ParseException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		payment.setId(id);
		payment.setStudent(student);
		payment.setMoney(money);
		payment.setNumber(paynumber);
		payment.setRemark(remark);
		
		System.out.println("save!!!!!!!!!!!!!!!!!!!!!");
		
		PaymentDao paymentDao = new PaymentDaoImpl();
		paymentDao.update(payment);
		
		response.sendRedirect("./tpayment.do");
	}

}
